/*!
 * \file StreamWriter.cpp
 * \date 12-7-2012 16:02:02
 * 
 * 
 * \author zjhlogo (zjhlogo@gmail.com)
 */
#include "../Inc/StreamWriter.h"

StreamWriter::StreamWriter()
{
	m_nPos = 0;
	m_vBuffer.resize(BLOCK_ALIGN);
}

StreamWriter::~StreamWriter()
{
	// TODO: 
}

bool StreamWriter::write(const void* pData, int nSize)
{
	if (!pData) return false;
	if (nSize <= 0) return true;

	if ((int)m_vBuffer.size() < m_nPos + nSize) m_vBuffer.resize(m_nPos + nSize);

	memcpy_s(&m_vBuffer[m_nPos],m_vBuffer.size()-m_nPos, pData, nSize);
	m_nPos += nSize;
	return true;
}

bool StreamWriter::write(int nPos, const void* pData, int nSize)
{
	if (!pData) return false;
	if (nSize <= 0) return true;

	if ((int)m_vBuffer.size() < nPos + nSize) m_vBuffer.resize(nPos + nSize);

	memcpy_s(&m_vBuffer[nPos],m_vBuffer.size()-nPos, pData, nSize);
	return true;
}

void StreamWriter::reset()
{
	m_nPos = 0;
}

const void* StreamWriter::getBuffer()
{
	return &m_vBuffer[0];
}

int StreamWriter::getBufferSize()
{
	return m_nPos;
}
